package sn.hn.demo.unit;

import java.util.Random;

import sn.hn.demo.MainActivity;
import sn.hn.demo.image.ImageData;
import sn.hn.demo.sprite.MySprite;
import android.content.Context;
import android.graphics.Bitmap;

public class Cloud extends Unit {
	public final int DELTA = 1;
	public Bitmap mCloud;
	public Bitmap mCloud1;
	public Bitmap mCloud2;
	public Bitmap mCloud3;
	public Bitmap mCloud4;
	public boolean isLeft;
	public boolean isDie;
	Random r = new Random();
	public MySprite mSprite;
	public Cloud(Context context) {
		super(context);
		this.isDie = false;
		this.isLeft = r.nextBoolean();
		getBitmap(context);
		initPosition();
		this.mSprite = new MySprite(this.x,this.y);
		init();
	}
	
	public void initPosition()
	{
		if(isLeft)
			this.x = MainActivity.SCREENWIDTH + r.nextInt(5);
		else
			this.x = -155;
		this.y = MainActivity.SCREENHEIGHT/6 + r.nextInt(10);
	}
	
	public void init()
	{
		switch (r.nextInt(30)%5) {
		case 0:
			this.mSprite.init(mCloud);
			break;
		case 1:
			this.mSprite.init(mCloud1);
			break;
		case 2:
			this.mSprite.init(mCloud2);
			break;
		case 3:
			this.mSprite.init(mCloud3);
			break;
		case 4:
			this.mSprite.init(mCloud4);
			break;
		default:
			this.mSprite.init(mCloud);
			break;
		}
	}
	
	public void getBitmap(Context context)
	{
		mCloud = ImageData.mCloud;
		mCloud1 = ImageData.mCloud1;
		mCloud2 = ImageData.mCloud2;
		mCloud3 = ImageData.mCloud3;
		mCloud4 = ImageData.mCloud4;
	}
	
	public void moveCloud()
	{
		if(!isDie)
		{
			if(isLeft){
				this.x -= DELTA;
				this.mSprite.yPos = this.y;
				this.mSprite.xPos = this.x;
			}
			else
			{
				this.x += DELTA;
				this.mSprite.yPos = this.y;
				this.mSprite.xPos = this.x;
			}
			if(this.x == -156 || this.x  == MainActivity.SCREENWIDTH + this.mSprite.src.getWidth())
			{
				this.isDie = true;
			}
		}
	}
}
